package com.yellowpage.ndc.dao;

import java.util.List;

import com.yellowpage.white.dao.BaseDaoHibernateImpl;

import com.yellowpage.ndc.data.Listing;

public class ListingDaoImpl extends BaseDaoHibernateImpl<Listing, Long> implements ListingDao {

	public ListingDaoImpl() {
		super(Listing.class);
	}		
		
	public Listing getListingByTel(String tel) {
		String queryString = "from Listing l where l.tel = '" + tel + "'";
		List listingList = getHibernateTemplate().find(queryString);
		if (listingList.size() > 0) {
			return (Listing) listingList.get(0);
		}
		return null;
	}
	
	public Listing getListingByRegionTel(String tel, String regionCode) {
		String queryString = " from Listing l, Address a " +
				" where l.addrId = a.addrId " +
				"   and l.tel = '" + tel + "'" +
				"   and a.regionCode = '" + regionCode + "'" ;
		List listingList = getHibernateTemplate().find(queryString);
		if (listingList.size() > 0) {
			return (Listing) listingList.get(0);
		}
		return null;
	}
	
}	